/*
 * Traphong.java
 *
 * Created on April 19, 2006, 5:41 PM
 */

package phs_project;
import phs_project.hotelForm;
import phs_project.digitalClock;
import phs_project.TableDataRoom;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.sql.*;
import java.sql.Connection;
import java.sql.Statement;
import javax.swing.JTable;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.util.*;
import java.util.Vector.*;
import java.text.Format;
import java.text.SimpleDateFormat;
/**
 *
 * @author  Administrator
 */
public class checkOutAll extends javax.swing.JDialog {
    
    /** Creates new form Traphong */
    public checkOutAll(JFrame parent,boolean check,String Order_ID) {
        super(parent,check);
        this.Order_ID=Order_ID;
        initComponents();
        txtOrderId.setText(Order_ID);
       //NgayTratruoc.setVisible(false);
        NgayTratruoc.setLocale(new Locale("vi"));
        txtOrderOfCus.setText(new publicClass().selectDateToString("select * from OrderOfCus where orderId='"+Order_ID+"'","CusName"));
        txtOrderDate.setText(new publicClass().selectDateToString("select * from OrderOfCus where orderId='"+Order_ID+"'","orderDate"));
        new digitalClock(txtCurrentDate);
        new publicClass().addItemToTable(tblRoomsInOrder,"select * from roomInorder where orderid='"+Order_ID+"'");
        new publicClass().hiddencol(tblRoomsInOrder,0);
        new publicClass().hiddencol(tblRoomsInOrder,1);
        new publicClass().hiddencol(tblRoomsInOrder,2);
        new publicClass().hiddencol(tblRoomsInOrder,4);
        new publicClass().hiddencol(tblRoomsInOrder,6);
        new publicClass().addItemToTable(tblServicesInOrderOnly,"select * from AllserviceInOrder where orderid='"+Order_ID+"'");
        new publicClass().hiddencol(tblServicesInOrderOnly,0);
        FillAllFeild ();
        /* sumCostOfRoomInOrder.setText(new publicClass().selectDateToString("select sum ([Thành tiền]) as TotalCostRoom from tinhtienphong where [mã đơn hàng]='"+txtOrderId.getText()+"'","TotalCostRoom"));      
        sumCostOfSVInOrder.setText(new publicClass().selectDateToString("sumofServices '"+txtOrderId.getText()+"'","sumSVR"));
        txtDiscount.setText(new publicClass().selectDateToString("select discount from orders where orderId='"+txtOrderId.getText()+"'","discount"));
        txtAddition.setText(new publicClass().selectDateToString("select addition from orders where orderId='"+txtOrderId.getText()+"'","addition"));
         txtAdd12.setText(new publicClass().selectDateToString("TinhTongTienDonHang "+txtOrderId.getText(),"TotalOd"));
          
         
         float Total = new Integer(txtAdd12.getText())+new Integer(txtAddition.getText())-new Integer(txtDiscount.getText())-new Integer(txtPay.getText());
        txtTotalSum.setText(Total+"");
//String [] title = {" ","Tên phòng","Ngày bắt đầu","Ngày kết thúc","Trạng thái"};
         //TableDataRoom tabledataroom = new TableDataRoom(Order_ID,title);
        //tableSearchOrder.setModel(tabledataroom);
         */
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblRoomsInOrder = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        NgayTratruoc = new com.toedter.calendar.JDateChooser();
        TratruocThoiHan = new javax.swing.JRadioButton();
        jButton5 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblCusInRoom = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblServicesInRoom = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        sumCostOfSVInOrder = new javax.swing.JTextField();
        sumCostOfRoomInOrder = new javax.swing.JTextField();
        txtAddition = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtDiscount = new javax.swing.JTextField();
        txtPay = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtTotalSum = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        txtAdd12 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtOrderId = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtOrderOfCus = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtOrderDate = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtCurrentDate = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tblServicesInOrderOnly = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Thanh to\u00e1n \u0111\u01a1n h\u00e0ng");
        setAlwaysOnTop(true);
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh s\u00e1ch ph\u00f2ng"));
        tblRoomsInOrder.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tblRoomsInOrder.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblRoomsInOrderMouseClicked(evt);
            }
        });

        jScrollPane3.setViewportView(tblRoomsInOrder);

        jButton1.setText("Tr\u1ea3 ph\u00f2ng");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        TratruocThoiHan.setText("Tr\u1ea3 tr\u01b0\u1edbc th\u1eddi h\u1ea1n");
        TratruocThoiHan.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        TratruocThoiHan.setMargin(new java.awt.Insets(0, 0, 0, 0));
        TratruocThoiHan.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TratruocThoiHanMouseClicked(evt);
            }
        });

        jButton5.setText("H\u1ee7y");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(TratruocThoiHan)
                    .add(jButton1))
                .add(32, 32, 32)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jButton5)
                    .add(NgayTratruoc, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(79, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 22, Short.MAX_VALUE)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(TratruocThoiHan)
                        .add(6, 6, 6)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jButton1)
                            .add(jButton5)))
                    .add(NgayTratruoc, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Kh\u00e1ch \u0111ang \u1edf"));
        tblCusInRoom.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tblCusInRoom);

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh s\u00e1ch d\u1ecbc v\u1ee5 g\u1ecdi theo ph\u00f2ng"));
        tblServicesInRoom.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(tblServicesInRoom);

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 73, Short.MAX_VALUE)
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Thanh to\u00e1n \u0111\u01a1n h\u00e0ng"));
        jLabel5.setText("T\u1ed5ng ti\u1ec1n DV");

        jLabel6.setText("Gi\u1ea3m gi\u00e1");

        jLabel7.setText("Ph\u1ee5 ph\u00ed");

        sumCostOfSVInOrder.setEditable(false);

        sumCostOfRoomInOrder.setEditable(false);

        jLabel8.setText("Kh\u00e1ch tr\u1ea3");

        txtPay.setText("0");

        jLabel10.setText("T\u1ed5ng ");

        jLabel11.setText("T\u1ed5ng ti\u1ec1n ph\u00f2ng");

        jButton3.setText("T\u00ednh");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        txtAdd12.setEditable(false);

        jLabel9.setText("C\u1ed9ng");

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel5)
                    .add(jLabel11)
                    .add(jLabel9)
                    .add(jLabel7))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(sumCostOfSVInOrder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .add(txtAdd12, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .add(sumCostOfRoomInOrder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .add(txtAddition, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
                .add(4, 4, 4)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel6)
                            .add(jLabel8))
                        .add(10, 10, 10)
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(txtPay)
                            .add(txtDiscount, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButton3)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                        .add(jLabel10)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(txtTotalSum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 83, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(jLabel6)
                    .add(sumCostOfSVInOrder, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(txtDiscount, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel11)
                    .add(sumCostOfRoomInOrder, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel8)
                    .add(txtPay, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel10)
                    .add(jLabel9)
                    .add(txtAdd12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(txtTotalSum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton3)
                    .add(txtAddition, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel7))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Th\u00f4ng tin \u0111\u01a1n h\u00e0ng")));
        jLabel1.setText("M\u00e3 \u0111\u01a1n h\u00e0ng");

        txtOrderId.setEditable(false);

        jLabel2.setText("Ng\u01b0\u1eddi \u0111\u1eb7t ");

        txtOrderOfCus.setEditable(false);

        jLabel3.setText("Ng\u00e0y \u0111\u1eb7t");

        txtOrderDate.setEditable(false);

        jLabel4.setText("H\u00f4m nay");

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(jLabel2))
                .add(37, 37, 37)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(txtOrderOfCus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 231, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(txtOrderId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(23, 23, 23)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel4)
                    .add(jLabel3))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(txtOrderDate)
                    .add(txtCurrentDate, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jLabel3)
                    .add(txtOrderDate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(txtOrderId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel2)
                    .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(txtOrderOfCus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabel4)
                        .add(txtCurrentDate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jButton2.setText("H\u1ee7y b\u1ecf");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton4.setText("Thanh to\u00e1n \u0111\u01a1n h\u00e0ng");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton6.setText("In h\u00f3a \u0111\u01a1n");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel6Layout = new org.jdesktop.layout.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(281, Short.MAX_VALUE)
                .add(jButton6)
                .add(15, 15, 15)
                .add(jButton4)
                .add(25, 25, 25)
                .add(jButton2)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel6Layout.createSequentialGroup()
                .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton2)
                    .add(jButton4)
                    .add(jButton6))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh s\u00e1ch d\u1ecbch v\u1ee5 chung"));
        tblServicesInOrderOnly.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane4.setViewportView(tblServicesInOrderOnly);

        org.jdesktop.layout.GroupLayout jPanel7Layout = new org.jdesktop.layout.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jPanel7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jPanel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
// TODO add your handling code here:
        //int OdId=new Integer(txtOrderId.getText());
        new purchard(this,true,txtOrderId.getText()).setVisible(true);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void FillAllFeild ()
    {
        sumCostOfRoomInOrder.setText(new publicClass().selectDateToString("select sum ([Thành tiền]) as TotalCostRoom from tinhtienphong where [mã đơn hàng]='"+txtOrderId.getText()+"'","TotalCostRoom"));      
        sumCostOfSVInOrder.setText(new publicClass().selectDateToString("sumofServices '"+txtOrderId.getText()+"'","sumSVR"));
        txtDiscount.setText(new publicClass().selectDateToString("select discount from orders where orderId='"+txtOrderId.getText()+"'","discount"));
        txtAddition.setText(new publicClass().selectDateToString("select addition from orders where orderId='"+txtOrderId.getText()+"'","addition"));
         txtAdd12.setText(new publicClass().selectDateToString("TinhTongTienDonHang "+txtOrderId.getText(),"TotalOd"));
          
         
         float Total = new Integer(txtAdd12.getText())+new Integer(txtAddition.getText())-new Integer(txtDiscount.getText())-new Integer(txtPay.getText());
        txtTotalSum.setText(Total+"");
    }
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
        UpdateOrder();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
       float Total = new Integer(txtAdd12.getText())+new Integer(txtAddition.getText())-new Integer(txtDiscount.getText())-new Integer(txtPay.getText());
       txtTotalSum.setText(Total+"");
        
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
         if (roomId==null)
        {
            JOptionPane.showMessageDialog(this,"Bạn phải chọn phòng !");
        }
        else
        {
             JOptionPane.showMessageDialog(this,"Hủy phòng !");
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
        if (roomId==null)
        {
            JOptionPane.showMessageDialog(this,"Bạn phải chọn phòng để trả");
        }
        else
        {   if (new Integer(roomStatus)!=4){
            
            if (new Integer(new publicClass().selectDateToString("tratruochaykhong '"+detaiId+"'","canPay"))==0){
            JOptionPane.showMessageDialog(this,"Bạn  không thể trả phòng khi mà khách đặt trước và chưa đến ở !");
            }
            if (new Integer(new publicClass().selectDateToString("tratruochaykhong '"+detaiId+"'","canPay"))==1)
            {
            JOptionPane.showMessageDialog(this,"Trả trước thời hạn!");  
                if (TratruocThoiHan.isSelected())
                {
                    int cf1 =  JOptionPane.showConfirmDialog(this,"Bạn có muốn trả phòng: "+roomName+" trước thời hạn vào ngày: "+new UserFormat().getFormat(NgayTratruoc.getDate(),"thongthuong")+" hay không ?","Thong bao",0);
                    if (cf1==0) {
                        
                        CheckOutRoom(roomId,roomName,txtOrderId.getText(),detaiId,new UserFormat().getFormat(NgayTratruoc.getDate(),"ngaygio"));
                        
                    }
                }
                else
                {
                    int cf =  JOptionPane.showConfirmDialog(this,"Bạn có muốn trả phòng: "+roomName+" vào ngày hôm nay hay không ?","Thông báo!",0);
                    if (cf==0) {
                         CheckOutRoom(roomId,roomName,txtOrderId.getText(),detaiId,"getDate()");
                    }
                }
            } // ngày hiện thời nằm trong khoảng thời gian có thể trả
         }
            else // phong da tra
            {
                JOptionPane.showMessageDialog(this,"Phòng: "+roomName+" đã được trả ! bạn kông thể thao tác được !");
            }
        }
        
    }//GEN-LAST:event_jButton1ActionPerformed
    private void CheckOutRoom(String RoomId,String RoomName,String OrderId,String DetailId ,String CheckOutDate)
    {
                    if (CheckOutDate.equals("getDate()"))
                    {
                        String sqltra="update orderdetail set enddate =getDate() where [id]='"+DetailId+"'";
                        new publicClass().SQLRUN(sqltra);
                    }
                    else
                    {
                         String sqltra="update orderdetail set enddate ='"+CheckOutDate+"' where [id]='"+DetailId+"'";
                         new publicClass().SQLRUN(sqltra);
                    }
                     String sqldele="delete roomcurent_detail where roomid='"+RoomId+"'";
                     String sqlChange = "update orderdetail set roomStatus=4 where [id]='"+DetailId+"'";
                    
                    new publicClass().SQLRUN(sqldele);
                    new publicClass().SQLRUN(sqlChange);
                    new publicClass().addItemToTable(tblRoomsInOrder,"select * from roomInorder where orderid='"+OrderId+"'");
                    new publicClass().hiddencol(tblRoomsInOrder,0);
                    new publicClass().hiddencol(tblRoomsInOrder,1);
                    new publicClass().hiddencol(tblRoomsInOrder,2);
                    new publicClass().hiddencol(tblRoomsInOrder,4);
                    new publicClass().hiddencol(tblRoomsInOrder,6);
                    sumCostOfRoomInOrder.setText(new publicClass().selectDateToString("select sum ([Tổng tiền]) as sumCOR from costofrooms where [Mã]='"+OrderId+"'","sumCOR"));      
                    FillAllFeild ();
                    JOptionPane.showMessageDialog(this,"Phòng: "+RoomName+" đã được trả!");
    }
    private void TratruocThoiHanMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TratruocThoiHanMouseClicked
// TODO add your handling code here:
        if (TratruocThoiHan.isSelected())
        {
            //NgayTratruoc.setVisible(true);
        }
        else
        {
            //NgayTratruoc.setVisible(false);
        }
        
    }//GEN-LAST:event_TratruocThoiHanMouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
        
        hotelForm.ODID=null;
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void tblRoomsInOrderMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblRoomsInOrderMouseClicked
// TODO add your handling code here:
        roomId = new publicClass().SelectedRowToString(tblRoomsInOrder,1);
        detaiId=new publicClass().SelectedRowToString(tblRoomsInOrder,2);
        roomName = new publicClass().SelectedRowToString(tblRoomsInOrder,3);
        roomStatus = new publicClass().SelectedRowToString(tblRoomsInOrder,4);
        ed = new publicClass().SelectedRowToString(tblRoomsInOrder,6);
        new publicClass().addItemToTable(tblCusInRoom,"select * from CustomerLiveInroom where roomid='"+roomId+"' and orderId='"+Order_ID+"'");
        new publicClass().hiddencol(tblCusInRoom,0);
        new publicClass().hiddencol(tblCusInRoom,1);
        new publicClass().addItemToTable(tblServicesInRoom,"select * from servicesInroom where roomid='"+roomId+"' and orderId='"+Order_ID+"'");
        new publicClass().hiddencol(tblServicesInRoom,0);
        new publicClass().hiddencol(tblServicesInRoom,1);
    }//GEN-LAST:event_tblRoomsInOrderMouseClicked
    
    private void UpdateOrder()
    
    {
        int countRoom = new Integer(new publicClass().selectDateToString("select count(roomId) as CountRoom from orderDetail where orderId='"+txtOrderId.getText()+"'","CountRoom"));
        int countRoomCheckedOut = new Integer(new publicClass().selectDateToString("select count(roomId) as CountRoom from orderDetail where orderId='"+txtOrderId.getText()+"' and (roomstatus=4 or roomstatus=7) ","CountRoom"));
       // int countRoomCheckedOut = new Integer(new publicClass().selectDateToString("select count(roomId) as CountRoom from orderDetail where orderId='"+txtOrderId.getText()+"' and roomstatus=4","CountRoom"));
        
        if (countRoom !=countRoomCheckedOut){
            
             new publicClass().SQLRUN(" update orders set conpleteDate =getDate(),disCount="+txtDiscount.getText()+",addition="+txtAddition.getText()+",totalfee="+txtTotalSum.getText()+",status=4 where orderID='"+txtOrderId.getText()+"'");
             JOptionPane.showMessageDialog(this,"Bạn vừa cập nhật thành công cho đơn hàng !");
            
        }
        else
        {
            new publicClass().SQLRUN(" update orders set conpleteDate =getDate(),disCount="+txtDiscount.getText()+",addition="+txtAddition.getText()+",totalfee="+txtTotalSum.getText()+",status=3 where orderID='"+txtOrderId.getText()+"'");
            JOptionPane.showMessageDialog(this,"Bạn vừa cập nhật thành công cho đơn hàng !");
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
              //  new Traphong().setVisible(true);
            }
        });
    }
    private String Order_ID ;
    private String roomId ;
    public String detaiId;
    private String roomName;
    private String roomStatus;
    private String ed;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.toedter.calendar.JDateChooser NgayTratruoc;
    private javax.swing.JRadioButton TratruocThoiHan;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextField sumCostOfRoomInOrder;
    private javax.swing.JTextField sumCostOfSVInOrder;
    private javax.swing.JTable tblCusInRoom;
    private javax.swing.JTable tblRoomsInOrder;
    private javax.swing.JTable tblServicesInOrderOnly;
    private javax.swing.JTable tblServicesInRoom;
    private javax.swing.JTextField txtAdd12;
    private javax.swing.JTextField txtAddition;
    private javax.swing.JTextField txtCurrentDate;
    private javax.swing.JTextField txtDiscount;
    private javax.swing.JTextField txtOrderDate;
    private javax.swing.JTextField txtOrderId;
    private javax.swing.JTextField txtOrderOfCus;
    private javax.swing.JTextField txtPay;
    private javax.swing.JTextField txtTotalSum;
    // End of variables declaration//GEN-END:variables
    
}
